home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************************
-
- MiniEdit.c
-
- ***********************************************************************************/
-
- /* NEEDED TO DEFINE NEW TEXTEDIT ROUTINES IN TEXTEDIT.H */
- #define __ALLNU__
-
- #include <QuickDraw.h>
- #include <Memory.h>
- #include <OSEvents.h>
- #include <Types.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Desk.h>
- #include <Files.h>
- #include <ToolUtils.h>
- #include <Controls.h>
- #include <resources.h>
- #include <strings.h>
- #include <Scrap.h>
-
- #include "MiniEdit.h"
- #include "TrapHook.h"
-
- #define DrawCharNum 0x085
- #define GetRes 0x1A0
-
- WindowRecord wRecord;
- WindowPtr myWindow;
- TEHandle TEH;
- Rect dragRect = { 0, 0, 1024, 1024 };
- MenuHandle myMenus[3];
- ControlHandle vScroll;
- Cursor editCursor;
- Cursor waitCursor;
- char dirty;
- EventRecord myEvent;
- int baseoffset = 0;
- TrapHookPointer InsertHookAddr;
- TrapHookPointer ResHook;
- long NormalTrap;
- long ResTrap;
-
- int currFontItem,currSizeItem;
-
- GetDrawTrapInfo();
- GetResTrapInfo();
- DrawTextHook();
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- main()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents( everyEvent, 0 );
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
-
- SetUpCursors();
- SetUpMenus();
- SetUpWindows();
-
- SetupHook(GetDrawTrapInfo,DrawTextHook,DrawCharNum,&InsertHookAddr,&NormalTrap);
- SetupHook(GetResTrapInfo,NULL,GetRes,&ResHook,&ResTrap);
-
- while (MainEvent());
-
- UnsetTrapHook(InsertHookAddr);
- UnsetTrapHook(ResHook);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doMouse(myEvent)
- EventRecord *myEvent;
- {
- WindowPtr whichWindow;
-
- switch (FindWindow( myEvent->where, &whichWindow ))
- {
- case inDesk:
- break;
- case inGoAway:
- if (ours(whichWindow))
- if (TrackGoAway( myWindow, myEvent->where) )
- { // CloseMyWindow();
- }
- break;
- case inMenuBar:
- return( DoCommand( MenuSelect(myEvent->where) ) );
- case inSysWindow:
- SystemClick( myEvent, whichWindow );
- break;
- case inDrag:
- if (ours(whichWindow))
- DragWindow( whichWindow, myEvent->where, &dragRect );
- break;
- case inGrow:
- if (ours(whichWindow))
- MyGrowWindow( whichWindow, myEvent->where );
- break;
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else
- if (ours(whichWindow))
- DoContent(whichWindow, myEvent);
- break;
- default: ;
- }
-
- return(1);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doKey(myEvent)
- EventRecord *myEvent;
- {
- register char theChar;
-
- theChar = myEvent->message & charCodeMask;
- if ((myEvent->modifiers & cmdKey) != 0)
- return( DoCommand( MenuKey( theChar ) ));
- else
- {
- TEKey( theChar, TEH );
- ShowSelect();
- }
-
- return(1);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doActivate(myEvent)
- EventRecord *myEvent;
- {
- Rect rct;
-
- if (ours((WindowPtr)myEvent->message))
- {
- myWindow = (WindowPtr)myEvent->message;
-
- rct = (*myWindow).portRect;
- rct.top = rct.bottom - (SBarWidth+1);
- rct.left = rct.left - (SBarWidth+1);
- InvalRect(&rct);
-
- if ( myEvent->modifiers & activeFlag )
- {
- TEActivate( TEH );
- ShowControl( vScroll );
- TEFromScrap();
- }
- else
- {
- TEDeactivate(TEH);
- HideControl( vScroll );
- ZeroScrap();
- TEToScrap();
- }
- }
-
- return(1);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- int MainEvent()
- {
- MaintainCursor();
- MaintainMenus();
-
- SetTrapAddress(NormalTrap,DrawCharNum);
- SetTrapAddress(ResTrap,GetRes);
-
- SystemTask();
-
- SetTrapAddress((long)&(InsertHookAddr->Code),DrawCharNum);
- SetTrapAddress((long)&(ResHook->Code),GetRes);
-
- TEIdle(TEH);
- if (GetNextEvent(everyEvent, &myEvent))
- {
- switch (myEvent.what)
- { case mouseDown:
- return(doMouse(&myEvent));
- break;
- case keyDown:
- case autoKey:
- return(doKey(&myEvent));
- break;
- case activateEvt:
- return(doActivate(&myEvent));
- break;
- case updateEvt:
- if (ours((WindowPtr)myEvent.message))
- UpdateWindow(myWindow);
- break;
- default: ;
- }
- }
-
- return(1);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- SetUpMenus()
- {
- int i;
-
- myMenus[appleM] = GetMenu(appleID);
- myMenus[fileM] = GetMenu(fileID);
- myMenus[editM] = GetMenu(editID);
-
- AddResMenu( myMenus[appleM], 'DRVR' );
-
- for ( (i=appleM); (i<=editM); i++ ) InsertMenu(myMenus[i], 0) ;
-
- CheckItem(myMenus[2],currFontItem=NewYorkCommand,1);
- CheckItem(myMenus[2],currSizeItem=s14Command,1);
-
- DrawMenuBar();
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doScrapEditing(theItem)
- int theItem;
- {
- switch (theItem)
- { case cutCommand:
- TECut( TEH );
- break;
- case copyCommand:
- TECopy( TEH );
- break;
- case pasteCommand:
- TEPaste( TEH );
- break;
- }
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doFontEditing(theItem)
- int theItem;
- {
- TextStyle Styl;
-
- CheckItem(myMenus[2],currFontItem,0);
- currFontItem = theItem;
- CheckItem(myMenus[2],currFontItem,1);
-
- switch (theItem)
- { case TimesCommand:
- Styl.tsFont = times;
- break;
- case GenevaCommand:
- Styl.tsFont = geneva;
- break;
- case NewYorkCommand:
- Styl.tsFont = newYork;
- break;
- }
- TESetStyle(doFont,&Styl,1,TEH);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doSizeEditing(theItem)
- int theItem;
- {
- TextStyle Styl;
-
- CheckItem(myMenus[2],currSizeItem,0);
- currSizeItem = theItem;
- CheckItem(myMenus[2],currSizeItem,1);
-
- switch (theItem)
- { case s9Command:
- Styl.tsSize = 9;
- break;
- case s10Command:
- Styl.tsSize = 10;
- break;
- case s12Command:
- Styl.tsSize = 12;
- break;
- case s14Command:
- Styl.tsSize = 14;
- break;
- case s18Command:
- Styl.tsSize = 18;
- break;
- }
- TESetStyle(doSize,&Styl,1,TEH);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doFaceEditing(theItem)
- int theItem;
- {
- TextStyle Styl;
- short lhgt,ascent;
-
- switch (theItem)
- { case plainCommand:
- Styl.tsFace = 0;
- break;
- case boldCommand:
- TEGetStyle((**TEH).selStart,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFace |= bold;
- break;
- case ulineCommand:
- TEGetStyle((**TEH).selStart,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFace |= underline;
- break;
- case italicCommand:
- TEGetStyle((**TEH).selStart,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFace |= italic;
- break;
- case shadowCommand:
- TEGetStyle((**TEH).selStart,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFace |= shadow;
- break;
- }
- TESetStyle(doFace,&Styl,1,TEH);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doScriptEditing(theItem)
- int theItem;
- {
- TextStyle Styl;
- short lhgt,ascent;
-
- switch (theItem)
- { case SuperCommand:
- TEGetStyle((**TEH).selStart-1,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFont &= REGULAR;
- Styl.tsFont |= SUPER;
- break;
- case RegularCommand:
- TEGetStyle((**TEH).selStart-1,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFont &= REGULAR;
- break;
- case SubCommand:
- TEGetStyle((**TEH).selStart-1,&Styl,&lhgt,&ascent,TEH);
- Styl.tsFont &= REGULAR;
- Styl.tsFont |= SUB;
- break;
- }
- TESetStyle(doFont,&Styl,1,TEH);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- doEditing(theItem)
- int theItem;
- {
- switch (theItem)
- { case cutCommand:
- case copyCommand:
- case pasteCommand:
- doScrapEditing(theItem);
- break;
-
- case TimesCommand:
- case GenevaCommand:
- case NewYorkCommand:
- doFontEditing(theItem);
- break;
-
- case s9Command:
- case s10Command:
- case s12Command:
- case s14Command:
- case s18Command:
- doSizeEditing(theItem);
- break;
-
- case plainCommand:
- case boldCommand:
- case ulineCommand:
- case italicCommand:
- case shadowCommand:
- doFaceEditing(theItem);
- break;
-
- case SuperCommand:
- case RegularCommand:
- case SubCommand:
- doScriptEditing(theItem);
- break;
-
- default: ;
- }
- ShowSelect();
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- int DoCommand( mResult )
- long mResult;
- {
- int theItem;
- Str255 name;
-
- theItem = LoWord( mResult );
- switch (HiWord(mResult))
- { case appleID:
- GetItem(myMenus[appleM], theItem, &name);
- OpenDeskAcc( &name );
- SetPort( myWindow );
- break;
- case fileID:
- if (theItem == fmQuit) return(0);
- break;
- case editID:
- if (SystemEdit(theItem-1)==0)
- doEditing(theItem);
- break;
- }
- HiliteMenu(0);
- return(1);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- MaintainCursor()
- {
- Point pt;
- WindowPeek wPtr;
- GrafPtr savePort;
- Rect TERect;
-
- wPtr = (WindowPeek)FrontWindow();
-
- if (ours(wPtr))
- { GetPort( &savePort );
- SetPort( (GrafPtr)wPtr );
-
- GetMouse(&pt);
- TERect = (**TEH).viewRect;
-
- if ( PtInRect(pt, &TERect) )
- SetCursor( &editCursor);
- else
- InitCursor();
-
- SetPort( savePort );
- }
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- MaintainMenus()
- {
- if ( !(*(WindowPeek)myWindow).visible ||
- !ours(FrontWindow()) )
- {
- EnableItem( myMenus[editM], cutCommand );
- EnableItem( myMenus[editM], copyCommand );
- }
- else
- {
- if ((**TEH).selStart==(**TEH).selEnd) {
- DisableItem( myMenus[editM], cutCommand );
- DisableItem( myMenus[editM], copyCommand );
- }
- else
- {
- EnableItem( myMenus[editM], cutCommand );
- EnableItem( myMenus[editM], copyCommand );
- }
- }
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- SetUpCursors()
- {
- CursHandle hCurs;
-
- hCurs = GetCursor(1);
- editCursor = **hCurs;
- hCurs = GetCursor(watchCursor);
- waitCursor = **hCurs;
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- ours(w)
- WindowPtr w;
- {
- return( (myWindow!=NULL) && (w==myWindow) );
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
-